package com.siwei.mes.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.ExperimentSampleSmokeLog;
import com.siwei.mes.mapper.ExperimentSampleSmokeLogMapper;
import com.siwei.mes.service.ExperimentSampleSmokeLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验台账抽样信息日志记录表(ExperimentSampleSmokeLog)表服务实现类
 *
 * @author linzi
 * @since 2024-01-01 13:54:02
 */
@Service
public class ExperimentSampleSmokeLogServiceImpl implements ExperimentSampleSmokeLogService {
    @Resource
    private ExperimentSampleSmokeLogMapper experimentSampleSmokeLogMapper;

    @Override
    public Long create(ExperimentSampleSmokeLog entity) {
        experimentSampleSmokeLogMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentSampleSmokeLog entity) {
        ExperimentSampleSmokeLog experimentSampleSmokeLog = experimentSampleSmokeLogMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentSampleSmokeLog == null, "试验台账抽样信息日志记录表信息不存在");
        experimentSampleSmokeLogMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentSampleSmokeLog experimentSampleSmokeLog = experimentSampleSmokeLogMapper.selectByPrimaryKey(id);
        assertTrue(experimentSampleSmokeLog == null, "试验台账抽样信息日志记录表信息不存在");
        experimentSampleSmokeLogMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentSampleSmokeLog> getPage(PageQuery<ExperimentSampleSmokeLog, ExperimentSampleSmokeLog> query) {
        ExperimentSampleSmokeLog searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentSampleSmokeLogMapper.getList(searchParam));
    }

    @Override
    public ExperimentSampleSmokeLog loadById(Long id) {
        return experimentSampleSmokeLogMapper.loadById(id);
    }

    @Override
    public List<ExperimentSampleSmokeLog> getAll(ExperimentSampleSmokeLog entity) {
        return experimentSampleSmokeLogMapper.getList(entity);
    }
}
